/*******************************************************************************
 * Copyright (c) 2010, 2017 西安秦晔信息科技有限公司
 * Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 *******************************************************************************/
package com.qinyeit.codegen.entity;

import org.apache.commons.lang3.StringUtils;

import java.io.File;

/**
 * ClassName: PropConfig <br/>
 * Function: 配置项 <br/>
 * date: 2017/3/15 14:38 <br/>
 *
 * @author 李洋
 * @since JDK 1.8
 */
public class PropConfig {

    private String projectPath = "";
    private String entry = "management"; //入口
    private String author="";//作者
    private String module="";//模块

    private boolean isModal = false;
    private boolean isTree = false;
    private boolean hasState = false;


    //项目名称
    private final String SERVICE_PROJECT_NAME="springstage-service";
    private final String WEB_PROJECT_NAME="springstage-web";
    private final String PAGE_PROJECT_NAME="springstage-page";
    //java代码存放路径
    private final String BASE_MAIN_SRC ="src/main/java";
    private final String BASE_TEST_SRC ="src/test/java";

    //基础包名
    private final String BASE_PACKAGE="com.qinyeit";
    private final String CORE_PACKAGE="com.qinyetech.springstage.core"; //核心包
    private final String ENTITY_BASE_PACKAGE=BASE_PACKAGE+".serviceapp.entity";//实体
    private final String REPOSITORY_BASE_PACKAGE=BASE_PACKAGE+".serviceapp.repository";//仓库
    private final String SERVICE_BASE_PACKAGE=BASE_PACKAGE+".serviceapp.service";//service
    private final String CONTROLLER_BASE_PACKAGE=BASE_PACKAGE+".webapp.controller";//controller
    //测试基础包
    private final String SERVICE_TEST_BASE_PACKAGE=BASE_PACKAGE+".serviceapp.test.service";
    private final String WEBAPP_TEST_BASE_PACKAGE=BASE_PACKAGE+".webapp";
    private final String CONTROLLER_TEST_BASE_PACKAGE=WEBAPP_TEST_BASE_PACKAGE+".test.controller";
    private final String CONTROLLER_TEST_CONFIG_BASE_PACKAGE=BASE_PACKAGE;


    //源代码基础路径
    private final String ENTITY_BASE_PACKAGE_PATH=SERVICE_PROJECT_NAME+"/"+BASE_MAIN_SRC+"/"+ ENTITY_BASE_PACKAGE.replace('.','/');
    private final String REPOSITORY_BASE_PACKAGE_PATH=SERVICE_PROJECT_NAME+"/"+BASE_MAIN_SRC+"/"+REPOSITORY_BASE_PACKAGE.replace('.','/');
    private final String SERVICE_BASE_PACKAGE_PATH=SERVICE_PROJECT_NAME+"/"+BASE_MAIN_SRC+"/"+SERVICE_BASE_PACKAGE.replace('.','/');
    private final String CONTROLLER_BASE_PACKAGE_PATH=WEB_PROJECT_NAME+"/"+BASE_MAIN_SRC+"/"+CONTROLLER_BASE_PACKAGE.replace('.','/');
    //Vue项目源码路径
    private final String VUE_BASE_SRC_PATH=PAGE_PROJECT_NAME+"/src";

    //测试代码基础路径
    private final String SERVICE_TEST_BASE_PACKAGE_PATH=SERVICE_PROJECT_NAME+"/"+BASE_TEST_SRC+"/"+SERVICE_TEST_BASE_PACKAGE.replace('.','/');
    private final String CONTROLLER_TEST_BASE_PACKAGE_PATH=WEB_PROJECT_NAME+"/"+BASE_TEST_SRC+"/"+CONTROLLER_TEST_BASE_PACKAGE.replace('.','/');
    private final String CONTROLLER_TEST_CONFIG_BASE_PACKAGE_PATH=WEB_PROJECT_NAME+"/"+BASE_TEST_SRC+"/"+CONTROLLER_TEST_CONFIG_BASE_PACKAGE.replace('.','/');



    private String ensurePathEnd(String path){
        return path.endsWith("/")?path:path+"/";
    }
    //////////////////////////////生成的文件所在的目录/////////////////////////////
    public String getEntityPath(){
        return ensurePathEnd(projectPath+"/"+ENTITY_BASE_PACKAGE_PATH);
    }
    public String getRepositoryPath(){
        return ensurePathEnd(projectPath+"/"+REPOSITORY_BASE_PACKAGE_PATH+(StringUtils.isBlank(module)?"":"/"+module));
    }
    public String getServicePath(){
        return ensurePathEnd(projectPath+"/"+SERVICE_BASE_PACKAGE_PATH+(StringUtils.isBlank(module)?"":"/"+module));
    }
    public String getServiceImplPath(){
        return ensurePathEnd(projectPath+"/"+SERVICE_BASE_PACKAGE_PATH+(StringUtils.isBlank(module)?"":"/"+module)+"/impl");
    }
    public String getControllerPath(){
        return ensurePathEnd(projectPath+"/"+CONTROLLER_BASE_PACKAGE_PATH+"/"+entry+(StringUtils.isBlank(module)?"":"/"+module));
    }
    public String getServiceTestPath(){
        return ensurePathEnd(projectPath+"/"+SERVICE_TEST_BASE_PACKAGE_PATH+(StringUtils.isBlank(module)?"":"/"+module));
    }
    public String getControllerTestPath(){
        return ensurePathEnd(projectPath+"/"+CONTROLLER_TEST_BASE_PACKAGE_PATH+"/"+entry+(StringUtils.isBlank(module)?"":"/"+module));
    }
    public String getControllerTestConfigPath(){
        return ensurePathEnd(projectPath+"/"+CONTROLLER_TEST_CONFIG_BASE_PACKAGE_PATH);
    }

    public String getVuePath(){
        return ensurePathEnd(projectPath+"/"+VUE_BASE_SRC_PATH+"/pages/");
    }
    public String getVueRouterPath(){
        return ensurePathEnd(projectPath+"/"+VUE_BASE_SRC_PATH+"/router/");
    }

    //////////////////////////包名///////////////////////
    public String getCorePackage(){
        return CORE_PACKAGE;
    }
    public String getEntityPackage(){
        return ENTITY_BASE_PACKAGE;
    }
    public String getRepositoryPackage(){
        return REPOSITORY_BASE_PACKAGE+(StringUtils.isBlank(module)?"":"."+module);
    }
    public String getBaseServicePackage(){
        return SERVICE_BASE_PACKAGE;
    }
    public String getServicePackage(){
        return SERVICE_BASE_PACKAGE+(StringUtils.isBlank(module)?"":"."+module);
    }
    public String getServiceImplPackage(){
        return SERVICE_BASE_PACKAGE+(StringUtils.isBlank(module)?"":"."+module)+".impl";
    }
    public String getControllerPackage(){
        return CONTROLLER_BASE_PACKAGE+"."+entry+(StringUtils.isBlank(module)?"":"."+module);
    }
    public String getServiceTestPackage(){
        return SERVICE_TEST_BASE_PACKAGE+(StringUtils.isBlank(module)?"":"."+module);
    }
    public String getControllerTestPackage(){
        return CONTROLLER_TEST_BASE_PACKAGE+"."+entry+(StringUtils.isBlank(module)?"":"."+module);
    }
    public String getControllerTestConfigPackage(){
        return CONTROLLER_TEST_CONFIG_BASE_PACKAGE;
    }
    ////////////////////////////////////////////


    public PropConfig(String projectPath,String entry,String author,String module) {
        this.projectPath = projectPath;
        this.entry=entry;
        this.author=author;
        this.module=module;
    }

    public String getProjectPath() {
        return projectPath;
    }

    public boolean isModal() {
        return isModal;
    }

    public void setModal(boolean modal) {
        this.isModal = modal;
    }

    public boolean isTree() {
        return isTree;
    }

    public void setTree(boolean tree) {
        this.isTree = tree;
    }

    public boolean isHasState() {
        return hasState;
    }

    public void setHasState(boolean hasState) {
        this.hasState = hasState;
    }

    public String getEntry() {
        return entry;
    }
    public String getEntryUpCase() {
        return StringUtils.capitalize(entry);
    }
    public String getModule(){
        return module;
    }
}
